package com.woniuxy.yogaapp.mapper;/*
 *@author：源
 *@date:17:06:11
 *@descripion
 */

import com.woniuxy.yogaapp.dto.Count;
import com.woniuxy.yogaapp.dto.UidDto;
import com.woniuxy.yogaapp.pojo.Appraise;
import com.woniuxy.yogaapp.pojo.DetailOrder;
import com.woniuxy.yogaapp.pojo.OrderClass;
import com.woniuxy.yogaapp.provider.OrderProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderShowMapper {

    //通过uid找到rid
    @Select("SELECT rid from user u INNER JOIN userroles us on u.uid=us.uid WHERE u.uid=#{uid}")
    public Integer selectRidByuid(UidDto uidDto);
    //已知sid或cid查order中所有信息
    @SelectProvider(method ="selectOrder",type = OrderProvider.class)
    @Results({
            @Result(id = true, column = "oid", property = "oid"),
            @Result(column = "sid",property = "sid"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "money",property = "money"),
            @Result(column = "course",property = "course"),
            @Result(column = "courseperioid",property = "courseperioid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "oid", property = "detailOrders",many =@Many(
                    select="findDetailByOid"
                    /*fetchType= FetchType.EAGER*/
            ))
    })
    public List<OrderClass> selectOrder(UidDto uidDto);

   @Select("select detailoid,transctionid,completime,otime,paytime,state,oid,apid from detailorder where oid=#{oid}")
   /*@Select("<script> " +
           "SELECT detailoid,transctionid,completime,otime,paytime,state,oid,apid  " +
           "FROM detailorder " +
           " <where> " +
           " <if test=\"pay\">state=6</if> " +

           " </where> " +
           " </script> ")*/
   @Results({
            @Result(id = true, column = "detailoid", property = "detailoid"),
            @Result(column = "transctionid",property = "transctionid"),
            @Result(column = "aprec",property = "aprec"),
            @Result(column = "completime",property = "completime"),
            @Result(column = "otime",property = "otime"),
            @Result(column = "paytime",property = "paytime"),
            @Result(column = "state",property = "state"),
            @Result(column = "oid",property = "oid"),
            @Result(column = "apid", property = "appraises",one =@One(
                    select="findAppraisesByApid"
                    /*fetchType= FetchType.EAGER*/
            ))
    })
    public List<DetailOrder> findDetailByOid(UidDto uidDto);
    @Select("select apid,apsender,aprec,mes,state,aptime from appraise where apid=#{apid}")
    public List<Appraise>  findAppraisesByApid(int apid);
    @Select("SELECT COUNT(state) count4 FROM orderclass o INNER JOIN detailorder d on o.oid=d.oid WHERE sid=#{sid} AND state=4")
    public Count selectCount4(int sid);
    @Select("SELECT COUNT(state) count6 FROM orderclass o INNER JOIN detailorder d on o.oid=d.oid WHERE sid=#{sid} AND state=6")
    public Count selectCount6(int sid);
    @Select("SELECT COUNT(state) countc FROM orderclass o INNER JOIN detailorder d on o.oid=d.oid WHERE cid=#{cid} AND state=1")
    public Count selectCountc(int cid);
}
